package com.tarena.lbs.business.service.impl;

import com.tarena.lbs.business.dao.repository.BusinessCategoryRepository;
import com.tarena.lbs.business.pojo.vo.BusinessCategoryVO;
import com.tarena.lbs.business.service.BusinessCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Service
public class BusinessCategoryServiceImpl implements BusinessCategoryService {
    @Autowired
    private BusinessCategoryRepository businessCategoryRepository;

    @Override
    public List<BusinessCategoryVO> allCategories() {
        log.info("开始查询所有商家分类");
        List<BusinessCategoryVO> voList = businessCategoryRepository.allCategories()
                .stream()
                .map(po -> {
                    BusinessCategoryVO vo = new BusinessCategoryVO();
                    BeanUtils.copyProperties(vo, po); // 注意参数顺序：目标在前
                    return vo;
                })
                .collect(Collectors.toList());
        log.info("共查询到 {} 条商家分类", voList.size());
        return voList;
    }
}